//
//  MeViewController.m
//  LiquorChain
//
//  Created by 王冬 on 2018/12/19.
//  Copyright © 2018年 王冬. All rights reserved.
//

#import "MeViewController.h"
#import "MeViewCell.h"
#import "SetUpViewController.h"
#import "BankViewController.h"
#import "AboutMyController.h"
#import "HelpCenterController.h"
#import "CustomerSerController.h"
#import "PublicGoodController.h"
#import "CashViewController.h"
#import "BusinessController.h"
#import "WalletViewController.h"
#import "WalletMeController.h"
#import "MyOrderViewController.h"
@interface MeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIImageView *headImageView;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *rankLabel;
@property (nonatomic,strong) NSArray *titleArray;
@end
@implementation MeViewController
static NSString *CellIdentifier = @"MECell";
-(NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray =[NSArray array];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, -kNavStausHeight, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"MeViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    self.titleArray = @[@"商家入驻申请",@"公益池",@"银行卡管理",@"关于我们",@"帮助中心",@"客服",@"设置"];
    [self creatHeadView];
    
    
    // Do any additional setup after loading the view.
}
-(void)creatHeadView{
    
    UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 407+kNavStausHeight)];
    backView.backgroundColor =[UIColor groupTableViewBackgroundColor];
    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 392 +kNavStausHeight)];
    headView.backgroundColor =[UIColor whiteColor];
    [backView addSubview:headView];
    UIView *topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 168)];
    topView.backgroundColor =[UIColor blackColor];
    [headView addSubview:topView];
    self.headImageView =[[UIImageView alloc]init];
    [topView addSubview:self.headImageView];
    self.headImageView.image =[UIImage imageNamed:@"item"];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = 27;
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(17);
        make.top.mas_equalTo(65);
        make.width.height.mas_equalTo(54);
    }];
    self.nameLabel =[[UILabel alloc]init];
    [topView addSubview:self.nameLabel];
    self.nameLabel.text = @"会员名";
    self.nameLabel.textColor =[UIColor whiteColor];
    self.nameLabel.font =[UIFont systemFontOfSize:20];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headImageView.mas_right).with.offset(7);
        make.top.mas_equalTo(70);
        make.height.mas_equalTo(19);
        
    }];
    self.rankLabel =[[UILabel alloc]init];
    [topView addSubview:self.rankLabel];
    self.rankLabel.text = @"酒链世界第211421位酿酒师";
    self.rankLabel.textColor =[UIColor whiteColor];
    self.rankLabel.font =[UIFont systemFontOfSize:13];
    [self.rankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).with.offset(9);
        make.left.mas_equalTo(self.headImageView.mas_right).with.offset(8);
        make.height.mas_equalTo(13);
    }];
    UIView *bodyView =[[UIView alloc]init];
    [headView addSubview:bodyView];
    bodyView.backgroundColor=[UIColor whiteColor];
    bodyView.layer.cornerRadius = 10;
    [bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headImageView.mas_bottom).with.offset(16);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(80);
    }];
    WDButton*waitFBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bodyView addSubview:waitFBtn];
    [waitFBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    waitFBtn.tag = 2000;
    waitFBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [waitFBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [waitFBtn setTitle:@"待付款" forState:UIControlStateNormal];
    [waitFBtn addTarget:self action:@selector(someClick:) forControlEvents:UIControlEventTouchUpInside];
    [waitFBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/5);
        make.height.mas_equalTo(50);
    }];
    
    WDButton*waitFaBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bodyView addSubview:waitFaBtn];
    waitFaBtn.tag = 2001;
    [waitFaBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    waitFaBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [waitFaBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [waitFaBtn setTitle:@"待发货" forState:UIControlStateNormal];
     [waitFaBtn addTarget:self action:@selector(someClick:) forControlEvents:UIControlEventTouchUpInside];
    [waitFaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(waitFBtn.mas_right).with.offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/5);
        make.height.mas_equalTo(50);
    }];
    
    WDButton*waitSBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bodyView addSubview:waitSBtn];
    waitSBtn.tag = 2002;
    [waitSBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    waitSBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [waitSBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [waitSBtn setTitle:@"待收货" forState:UIControlStateNormal];
     [waitSBtn addTarget:self action:@selector(someClick:) forControlEvents:UIControlEventTouchUpInside];
    //[waitFBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:1];
    [waitSBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(waitFaBtn.mas_right).with.offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/5);
        make.height.mas_equalTo(50);
    }];
    
    
    WDButton*orderBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bodyView addSubview:orderBtn];
    orderBtn.tag = 2003;
    [orderBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    //orderBtn.backgroundColor =[UIColor redColor];
    orderBtn.titleLabel.font =[UIFont systemFontOfSize:14];
    [orderBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     [orderBtn addTarget:self action:@selector(someClick:) forControlEvents:UIControlEventTouchUpInside];
    [orderBtn setTitle:@"我的订单" forState:UIControlStateNormal];
    [orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/5);
        make.height.mas_equalTo(50);
    }];
    UILabel *linLabel =[[UILabel alloc]init];
    linLabel.backgroundColor =[UIColor groupTableViewBackgroundColor];
    [bodyView addSubview:linLabel];
    [linLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(waitSBtn.mas_right).with.offset(10);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(0.5);
    }];
    UIImageView *centerView =[[UIImageView alloc]init];
    centerView.backgroundColor =[UIColor yellowColor];
    centerView.userInteractionEnabled = YES;
    [headView addSubview:centerView];
    centerView.layer.cornerRadius = 10;
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bodyView.mas_bottom).with.offset(18);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(90);
    }];
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [centerView addSubview:rightBtn];
    [rightBtn setImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(walletClick:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(10);
        make.width.mas_equalTo(100);
    }];
    
    UIButton *walletBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    //[walletBtn setImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
    [walletBtn setTitle:@"钱包地址qweqeqweqweqw" forState:UIControlStateNormal];
    [walletBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [walletBtn addTarget:self action:@selector(walletLeftbtn:) forControlEvents:UIControlEventTouchUpInside];
    [centerView addSubview:walletBtn];
    [walletBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-110);

    }];
    
    UIView *bottomView =[[UIView alloc]init];
    [headView addSubview:bottomView];
    // bottomView.backgroundColor =[UIColor ];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(centerView.mas_bottom).with.offset(20);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(80);
    }];
    
    WDButton*powerBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bottomView addSubview:powerBtn];
    powerBtn.tag = 2004;
    [powerBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    powerBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [powerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [powerBtn setTitle:@"酿力" forState:UIControlStateNormal];
    [powerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/4);
        make.height.mas_equalTo(50);
    }];
    
    
    WDButton*moneyBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bottomView addSubview:moneyBtn];
    moneyBtn.tag = 2005;
    [moneyBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    //moneyBtn.backgroundColor =[UIColor greenColor];
    moneyBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [moneyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [moneyBtn addTarget:self action:@selector(someClick:) forControlEvents:UIControlEventTouchUpInside];
    [moneyBtn setTitle:@"现金" forState:UIControlStateNormal];
    [moneyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(powerBtn.mas_right).with.offset(0);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/4);
        make.height.mas_equalTo(50);
    }];
    
    WDButton*marketBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bottomView addSubview:marketBtn];
    marketBtn.tag = 2006;
    [marketBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    marketBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [marketBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [marketBtn setTitle:@"圣酒市场" forState:UIControlStateNormal];
    [marketBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(moneyBtn.mas_right).with.offset(0);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/4);
        make.height.mas_equalTo(50);
    }];
    WDButton*orderJIUBtn =[WDButton buttonWithType:UIButtonTypeCustom];
    [bottomView addSubview:orderJIUBtn];
    orderJIUBtn.tag = 2007;
    [orderJIUBtn setImage:[UIImage imageNamed:@"waitF"] forState:UIControlStateNormal];
    orderJIUBtn.titleLabel.font =[UIFont systemFontOfSize:12];
    [orderJIUBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [orderJIUBtn setTitle:@"圣酒交易订单" forState:UIControlStateNormal];
    [orderJIUBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(marketBtn.mas_right).with.offset(0);
        make.width.mas_equalTo((SCREEN_WIDTH-30)/4);
        make.height.mas_equalTo(50);
    }];
    
    
    self.tableView.tableHeaderView = backView;
}
-(void)walletLeftbtn:(UIButton *)sender{
    NSLog(@"");
    WalletMeController *wallMeVC =[[WalletMeController alloc]init];
    wallMeVC.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController pushViewController:wallMeVC animated:YES];
    
}
-(void)walletClick:(UIButton *)sender{
    NSLog(@"123");
    WalletViewController *wallVC =[[WalletViewController alloc]init];
    wallVC.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController pushViewController:wallVC animated:YES];
    
}
-(void)someClick:(UIButton *)sender{
    if (sender.tag == 2000) {
        MyOrderViewController *myorderVC =[[MyOrderViewController alloc]init];
        myorderVC.index = 1;
        myorderVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:myorderVC animated:YES];
    }
    if (sender.tag == 2001) {
        MyOrderViewController *myorderVC =[[MyOrderViewController alloc]init];
        myorderVC.index = 2;
        myorderVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:myorderVC animated:YES];
    }
    if (sender.tag == 2002) {
        MyOrderViewController *myorderVC =[[MyOrderViewController alloc]init];
        myorderVC.index = 3;
        myorderVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:myorderVC animated:YES];
    }
    if (sender.tag == 2003) {
        MyOrderViewController *myorderVC =[[MyOrderViewController alloc]init];
        myorderVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:myorderVC animated:YES];
    }
    if (sender.tag == 2005) {
        CashViewController *cashVC =[[CashViewController alloc]init];
        cashVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:cashVC animated:YES];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  7;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.nameLabel.text = self.titleArray[indexPath.row];
    if (indexPath.row ==0) {
        cell.infoLabel.text= @"(圣酒庄园商家)";
    }
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row ==0) {
        BusinessController *businessVC =[[BusinessController alloc]init];
        businessVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:businessVC animated:YES];
    }
    if (indexPath.row ==1) {
        PublicGoodController *pubgoodVC =[[PublicGoodController alloc]init];
        pubgoodVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:pubgoodVC animated:YES];
    }
   
    
    if (indexPath.row ==2) {
        BankViewController *bankVC =[[BankViewController alloc]init];
        bankVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:bankVC animated:YES];
    }
    if (indexPath.row ==3) {
        AboutMyController *aboutVC =[[AboutMyController alloc]init];
        aboutVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:aboutVC animated:YES];
    }
    if (indexPath.row ==4) {
        HelpCenterController *helpVC =[[HelpCenterController alloc]init];
        helpVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:helpVC animated:YES];
    }
    if (indexPath.row ==5) {
        CustomerSerController *custVC =[[CustomerSerController alloc]init];
        custVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:custVC animated:YES];
    }
    if (indexPath.row ==6) {
        SetUpViewController *setupVC =[[SetUpViewController alloc]init];
        setupVC.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:setupVC animated:YES];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = NO;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}



@end
